﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Entities
{
    public class QuanLyTaiKhoan
    {


        public static TaiKhoan taiKhoanHienTai { set; get; }

        public static void phanTichQuyen(){
            if (taiKhoanHienTai != null)
            {
                int[] array = new int[4];
                int tempQuyen = taiKhoanHienTai.quyen;

                for (int i = 8, j = 0; i >= 1; i = i / 2, j++)
                {
                    if (tempQuyen > 0 )
                    {
                        if (tempQuyen < i)
                        {
                            continue;
                        }

                        if (j == 3)
                        {
                            taiKhoanHienTai.xem = true;
                        }
                        else if (j == 2)
                        {
                            taiKhoanHienTai.them = true;
                        }
                        else if (j == 1)
                        {
                            taiKhoanHienTai.xoa = true;

                        }
                        else if (j == 0)
                        {
                            taiKhoanHienTai.sua = true;
                        }
                        //array[j] = i;
                        tempQuyen = tempQuyen - i;
                    }
                }
             }
        }
        // neu la admin thi them vao tat ca cac phuong thuc duoi ///
        public static bool taiKhoanONhomXemThemXoaSuaOPhongKeHoach()
        {
            //if (taiKhoanHienTai.xem && 
            //    taiKhoanHienTai.them && 
            //    taiKhoanHienTai.xoa && 
            //    taiKhoanHienTai.sua &&
            if (
                taiKhoanHienTai.maPhongBan == (int)PhongBan.PhongKeHoach ||
                taiKhoanHienTai.maPhongBan == (int)PhongBan.GiamDoc
               )
            {
                return true;
            }
            return false;
        }

        public static bool taiKhoanONhomXemThemXoaSuaPhongSanXuat()
        {
            if (taiKhoanHienTai.maPhongBan == (int)PhongBan.PhongSanXuat ||
                taiKhoanHienTai.maPhongBan == (int)PhongBan.GiamDoc
                )
            {
                return true;
            }
            return false;
        }

        public static bool taiKhoanONhomXemThemXoaSuaPhongCongNghe()
        {
            if (taiKhoanHienTai.maPhongBan == (int)PhongBan.PhongCongNghe ||
                taiKhoanHienTai.maPhongBan == (int)PhongBan.GiamDoc
                )
            {
                return true;
            }
            return false;
        }

        public static bool taiKhoanONhomXemThemXoaSuaPhongChatLuong()
        {
            if (taiKhoanHienTai.maPhongBan == (int)PhongBan.PhongChatLuong ||
                taiKhoanHienTai.maPhongBan == (int)PhongBan.GiamDoc
                )
            {
                return true;
            }
            return false;
        }

        public static bool taiKhoanONhomXemThemXoaSuaPhongThongKe()
        {
            if (taiKhoanHienTai.maPhongBan == (int)PhongBan.PhongThongKe ||
                taiKhoanHienTai.maPhongBan == (int)PhongBan.GiamDoc
                )
            {
                return true;
            }
            return false;
        }
        
        public enum PhanQuyen
        {
            XEM = 1,
            THEM = 2,
            XOA = 4,
            SUA = 8
        }

        public enum PhongBan
        {
            GiamDoc = 1,
            PhongKeHoach = 2,
            PhongCongNghe = 3,
            PhongSanXuat = 4,
            PhongThongKe = 5,
            PhongChatLuong = 6
        }
    }
}

